/**
 * 
 */
package com.winit.openapi.isp.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.winit.oms.spi.isp.ISPOrderErrorMsgService;
import com.winit.oms.spi.isp.command.order.GetByOrderNoCommand;
import com.winit.oms.spi.isp.vo.OrderErrorMsg;
import com.winit.openapi.constants.ErrorCode;
import com.winit.openapi.controller.BaseController;
import com.winit.openapi.exception.ApiException;
import com.winit.openapi.model.RequestMsg;
import com.winit.openapi.model.ResponseMsg;

/**
 * 订单校验异常信息表
 * 
 * @author hui.li2 2015年6月2日 下午8:07:47
 * @since 1.0
 */
@Controller
@RequestMapping(value = "/isp/orderErrorMsg")
public class ISPOrderErrorMsgController extends BaseController {

    @Resource
    private ISPOrderErrorMsgService iSPOrderErrorMsgService;

    /**
     * 根据ordderID查询订单错误消息
     * 
     * @param requestMsg
     * @param responseMsg
     * @return
     */
    @RequestMapping(value = "/getISPOrderErrorMsg")
    public String getISPOrderErrorMsg(@ModelAttribute RequestMsg requestMsg, @ModelAttribute ResponseMsg responseMsg) {
        Object obj = requestMsg.getData();
        GetByOrderNoCommand command = new GetByOrderNoCommand();
        if (obj instanceof JSONObject) {
            JSONObject json = (JSONObject) obj;
            if (json.containsKey("orderNo")) {
                command.setOrderNo(json.getString("orderNo"));
            }
        } else {
            throw new ApiException(ErrorCode.FIELD_TYPE_ERROR, "data");
        }
        List<OrderErrorMsg> oemList = iSPOrderErrorMsgService.getISPOrderErrorMsgByOrderId(command);
        
        if (oemList != null) {
            
            responseMsg.setData(oemList);
        }
        return SUCCESS;
    }

}
